package saucaca.fragment;

import java.util.ArrayList;

import saucaca.Adapter.SongQueueAdapter;
import saucaca.Object.SongObject;
import saucaca.Service.MusicService;
import saucaca.Service.PlaylistManager;
import saucaca.Service.Singleton;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.lemon.kenhnhacvn.MainActivity;
import com.lemon.kenhnhacvn.R;


public class MainListeningPlaylistQueue extends Fragment{

	ListView listView;
	Context context;
	ArrayList<SongObject> listsongs;
	public SongQueueAdapter adapterQueueAdapter;
	
	public static MainListeningPlaylistQueue newInstance(ArrayList<SongObject> listsongs) {
		MainListeningPlaylistQueue f = new MainListeningPlaylistQueue();
		Bundle args = new Bundle();
		args.putSerializable(MainActivity.ID, listsongs);
		f.setArguments(args);
		return f;
	}
	
//	public MainListeningPlaylistQueue(Context context, ArrayList<SongObject> listsongs) {
//		this.context=context;
//		this.listsongs=listsongs;
//		adapterQueueAdapter=new SongQueueAdapter(context, listsongs);
//	}
	public void update( ArrayList<SongObject> listsongs,int index){
		adapterQueueAdapter.setListSong(listsongs);
		adapterQueueAdapter.setPotitionIndicator(index);
	}
	@SuppressWarnings("unchecked")
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.listening_playlist_queue, container, false);
		findviewbyid(view);
		listsongs =new ArrayList<SongObject>();
		this.context=getActivity();
		if (getArguments() != null) {
			Bundle b = getArguments();
			listsongs = (ArrayList<SongObject>) b.getSerializable(MainActivity.ID);
		}
		adapterQueueAdapter=new SongQueueAdapter(context, listsongs);
		listView.setAdapter(adapterQueueAdapter);
		return view;
	}
	void findviewbyid(View view){
		listView=(ListView) view.findViewById(R.id.listViewQueue);
	}
	@Override
	public void onResume() {
		try {
			update(Singleton.getInstance().getNowPlayingList(), Singleton.getInstance().getCurrentIndex());
		} catch (Exception e) {
		}
		super.onResume();
	}
}
